package com.komodo.island.gdx.dialog;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.actors.Image;
import com.komodo.island.gdx.Input;
import com.komodo.island.gdx.KomodoIsland;
import com.komodo.island.gdx.screen.Screen;

public class LoadingDialog extends Dialog {

	public float currTime;
	public int loadingState = 0;
	public Image[] loadingImage;

	public LoadingDialog(float width, float height, boolean stretch,
			Screen screen, Texture texture,KomodoIsland komodoIsland) {
		super(width, height, stretch, screen, texture,komodoIsland);
		// TODO Auto-generated constructor stub
		ID = Input.DIALOG_LOADING;
	}

	@Override
	public void init() {
		// TODO Auto-generated method stub
		// textureName = Constants.dialogTexName;
		// initByName();
		// setBackground(0, 0, 480, 320);
		loadingImage = new Image[4];

		loadingImage[0] = new Image("loading0", new TextureRegion(
				komodoIsland.dialogTexture, 0, 194, 75, 20));
		loadingImage[1] = new Image("loading1", new TextureRegion(
				komodoIsland.dialogTexture, 75, 194, 75, 20));
		loadingImage[2] = new Image("loading2", new TextureRegion(
				komodoIsland.dialogTexture, 150, 194, 75, 20));
		loadingImage[3] = new Image("loading3", new TextureRegion(
				komodoIsland.dialogTexture, 150 + 75, 194, 75, 20));

	}

	@Override
	public void addElements() {
		// TODO Auto-generated method stub
		addActor(loadingImage[0]);
	}

	@Override
	public void setThePosition() {
		// TODO Auto-generated method stub

	}

	@Override
	public void setTheListener() {
		// TODO Auto-generated method stub

	}

	@Override
	public void draw() {
		// TODO Auto-generated method stub
		super.draw();
		currTime = System.currentTimeMillis();
		if (Math.round(currTime) % 1000 == 0) {
			if (loadingState < 3) {
				loadingState++;
				this.addActor(loadingImage[loadingState]);

			} else {
				this.removeActor(loadingImage[loadingState]);
				loadingState = 0;
				this.addActor(loadingImage[loadingState]);
			}
		}

	}

}
